﻿//-----------------------------------------------------------------------
// <copyright file="RaceHelper.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System;
using GateShift.Common.Repository.Interfaces.DataInterfaces;
using GateShift.Common.Repository.Interfaces.Repositories;
using GateShift.Services.GameData.Entities;

#endregion

namespace GateShift.Testing.Services.GameData.Helpers
{
    /// <summary>
    /// Static Unit Test Helper Class for Race Entities
    /// </summary>
    internal static class RaceHelper
    {
        /// <summary>
        /// Creates a completely random and unique race name
        /// </summary>
        /// <returns></returns>
        public static string CreateRandomRaceName()
        {
            return Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 20);
        }

        /// <summary>
        /// Creates a race ready to save to the database
        /// </summary>
        /// <returns>Race with unique default values</returns>
        public static IRaceData CreateRace()
        {
            Race race = new Race();
            Random rnd = new Random();

            race.Name = CreateRandomRaceName();

            // Random ability modifiers
            race.ModifierAccuracy = (byte)rnd.Next(0, 255);
            race.ModifierAgility = (byte)rnd.Next(0, 255);
            race.ModifierEndurance = (byte)rnd.Next(0, 255);
            race.ModifierEnergy = (byte)rnd.Next(0, 255);
            race.ModifierForce = (byte)rnd.Next(0, 255);
            race.ModifierInsight = (byte)rnd.Next(0, 255);
            race.ModifierIntellect = (byte)rnd.Next(0, 255);
            race.ModifierStrength = (byte)rnd.Next(0, 255);
            race.ModifierWill = (byte)rnd.Next(0, 255);

            return race;
        }

        /// <summary>
        /// Creates a race ready pre-saved to the database
        /// </summary>
        /// <returns>Race with unique default values</returns>
        public static IRaceData CreateDBRace()
        {
            Race race = (Race)CreateRace();

            DBHelper.Provider.GetRepository<IRaceRepository>().Save(race);

            return race;
        }
    }
}